package xyz.xuminghai.javafx_learn.scene.shape;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.SVGPath;
import javafx.stage.Stage;

/**
 * 2023/8/10 22:28 星期四<br/>
 * SVGPath类表示通过从字符串解析 SVG 路径数据来构造的简单形状
 *
 * @author xuMingHai
 */
public class SVGPathApp extends Application {

    private final BorderPane root = new BorderPane();


    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {
        SVGPath svgPath1 = new SVGPath();
        svgPath1.setContent("""
                M101.1,84.5c1.6-1.6,4.1-1.6,5.6,0c0,0,0,0,0,0l8.8,8.8c1.6,1.5,1.6,4.1,0,5.6c-1,1-2.5,1.4-3.9,1l-5.4,10.4
                	c-0.3,0.5-0.8,0.9-1.3,1l-0.1,0l-16.8,2c-0.7,0.1-1.3-0.4-1.3-1.1c0-0.1,0-0.1,0-0.2l0-0.1l2-16.8c0.1-0.6,0.4-1.1,0.9-1.4l0.1-0.1
                	l10.4-5.4C99.7,87,100.1,85.5,101.1,84.5z M101.3,90.4L91,95.8l-1.6,13.3l4.4-4.4c0.4-0.4,1.1-0.4,1.5,0c0.4,0.4,0.4,1,0.1,1.4
                	l-0.1,0.1l-4.4,4.4l13.3-1.5l5.4-10.4L101.3,90.4z M105,86.2c-0.6-0.6-1.6-0.6-2.2,0s-0.6,1.6,0,2.2l0,0l8.8,8.8
                	c0.6,0.6,1.6,0.6,2.2,0s0.6-1.6,0-2.2l0,0L105,86.2z
                """);
        svgPath1.setStroke(Color.BLUE);

        SVGPath svgPath2 = new SVGPath();
        svgPath2.setContent("""
                M102.1,97.9c-1.3-1.3-3.5-1.3-4.9,0s-1.3,3.5,0,4.9l0,0c1.3,1.3,3.5,1.3,4.9,0S103.4,99.3,102.1,97.9z M100.6,99.4
                	c0.5,0.5,0.6,1.4,0,2c-0.5,0.5-1.4,0.6-2,0c-0.5-0.5-0.6-1.4,0-2C99.2,98.9,100.1,98.9,100.6,99.4L100.6,99.4z
                """);
        svgPath2.setFill(Color.RED);

        Group svgGroup = new Group(svgPath1, svgPath2);
        System.out.println("svgGroup.getLayoutBounds() = " + svgGroup.getLayoutBounds());

        root.setCenter(svgGroup);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
